package com.boarsoft.boar.soagov.protocol.biz;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boarsoft.boar.soagov.entity.ProtocolInfo;
import com.boarsoft.boar.soagov.protocol.ProtocolInfoBiz;
import com.boarsoft.common.Util;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.hibernate.biz.SimpleBizImpl;

@Component("ProtocolInfoBiz")
public class ProtocolInfoBizImpl extends SimpleBizImpl implements ProtocolInfoBiz {

	@Override
	@Transactional(readOnly = true)
	public PagedResult<ProtocolInfo> list(String projectId, String key, String orderBy, int pageNo, int pageSize) {
		StringBuilder sb = new StringBuilder();
		if (Util.strIsNotEmpty(projectId)) {
			sb.append(" and projectId='").append(projectId).append("'");
		}
		int total = dao.getTotal(ProtocolInfo.class, sb.toString());
		List<ProtocolInfo> lt = dao.list(ProtocolInfo.class, sb.toString(), pageNo, pageSize);
		return new PagedResult<ProtocolInfo>(total, lt, pageNo, pageSize);
	}

	@Override
	@Transactional
	public void save(ProtocolInfo o) {
		dao.save(o);
	}

	@Override
	@Transactional
	public void update(ProtocolInfo o) {
		dao.merge(o);
	}

	@Override
	@Transactional
	public void delete(String id) {
		dao.delete(ProtocolInfo.class, id);
	}

	@Override
	@Transactional(readOnly = true)
	public ProtocolInfo get(String id) {
		return (ProtocolInfo) dao.get(ProtocolInfo.class, id);
	}
}
